// ============================== 导入依赖 ============================== //

import CORE from '@login/CORE'
import Client from '@api/base/api/MessageAlarmGroupApi'

import TreeClass from '@api/base/model/MessageAlarmGroupReq'

const CLIENT = CORE.grpcCLIENT(Client)

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 结构树 —————————————————————————————— //

  async getTree(treeParam, TIP = '查询结构树') {
    const DTO = CORE.grpcDTO(TreeClass, treeParam)
    const resp = await CORE.grpc(TIP, CLIENT, 'messageAlarmGroupQuery', DTO)
    return resp.content || []
  },
  transTree(arr) {
    arr.forEach((major) => {
      Object.assign(major, {
        type: 1,
        name: major.subSystemName,
        code: major.subSystemCode,
        parentCode: '',
      })

      major.children.forEach((minor) => {
        Object.assign(minor, {
          type: 2,
          name: minor.alarmTypeName,
          code: minor.alarmTypeCode,
          parentCode: major.subSystemCode,
        })
      })
    })
    return arr
  },
}
